﻿using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace svnbox {
    static class Program {
        [STAThread]
        static void Main() {
            try {
                new SIApplication().Run(new string[0]);
            } catch (UnauthorizedAccessException) {
                MessageBox.Show("Svnbox  is already running in background by some other user. New instance cannot be started.", "Advanced FTP Server");
            }
        }
    }

    class SIApplication : WindowsFormsApplicationBase {
        public SIApplication() {
            //
            //this.IsSingleInstance = true;
            this.EnableVisualStyles = true;

            this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
            this.StartupNextInstance += new StartupNextInstanceEventHandler(this.Application_NewInstance);
        }

        protected override void OnCreateMainForm() {
            App.Load();
            this.MainForm = new frmMain();            
        }

        protected void Application_NewInstance(object sender, StartupNextInstanceEventArgs eventArgs) {
            this.MainForm.Invoke(new frmMain.ProcessNewInstanceDelegate(((frmMain)this.MainForm).ProcessNewInstance));
        }
    }
}
